package com.knowledge.plus.单例多例.单例;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * springboot 单例
 *
 * @author PF.Tian
 * @since 2021/09/13
 */
@RestController
@RequestMapping("request")
public class SingletonController {

    /**
     * 单例情况：
     * 静态变量和非静态变量都被共用
     */
    public static Integer staInvoiceCount = 0;
    public Integer invoiceCount = 0;

    @GetMapping("/test1")
    public String index() {
        return "staInvoiceCount = " + (++staInvoiceCount) + " , invoiceCount= " + (++invoiceCount);

    }
}
/*
    结果：
    第一次请求：staInvoiceCount = 1 , invoiceCount = 1
    第二次请求：staInvoiceCount = 2 , invoiceCount = 2
    第三次请求：staInvoiceCount = 3 , invoiceCount = 3

    结论：单例情况：静态变量和非静态变量都被共用
*/
